package work20241128;

import java.util.Arrays;

/**
 * @author zdl
 * @date 2024/11/28
 */
public class Demo7 {
    public static void main(String[] args) {
        //写一个方法 用于合并两个int类型的数组  合并,去重,并排序
        int[] arr = {1, 2, 5, 3, 8, 9};
        int[] arr1 = {1, 3, 0};
        int[] s = test(arr, arr1);
        System.out.println(Arrays.toString(s));

    }

    public static int[] test(int[] arr, int[] arr1) {
        int[] newArr = new int[arr.length + arr1.length];
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            newArr[index++] = arr[i];
        }
        for (int i = 0; i < arr1.length; i++) {
            newArr[index++] = arr1[i];
        }
        //System.out.println(Arrays.toString(newArr));
        //去重
        int len = newArr.length;
        for (int i = 0; i < len; i++) {
            for (int j = i+1; j < len; j++) {
                if (newArr[i] == newArr[j]) {
                    newArr[j] = newArr[len - 1];
                    len--;
                    j--;
                }
            }
        }
        int[] new_new_arr = new int[len];
        for (int i = 0; i < new_new_arr.length; i++) {
            new_new_arr[i] = newArr[i];
        }
        //System.out.println(Arrays.toString(new_new_arr));
        //排序
        for (int i = 0; i < new_new_arr.length-1; i++) {
            for (int j = 0; j < new_new_arr.length-1-i; j++) {
                if (new_new_arr[j] > new_new_arr[j + 1]) {
                    int temp = new_new_arr[j];
                    new_new_arr[j] = new_new_arr[j + 1];
                    new_new_arr[j + 1] = temp;
                }
            }
        }
       // System.out.println(Arrays.toString(new_new_arr));
        return new_new_arr;
    }
}
